package carlyang;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.sun.webkit.ThemeClient;

class Student{
	private String name;
	private int age;
	
	
	public Student(int age) {
		this.age = age;
	}
	public Student(String name) {
		this.name = name;
	}
	public Student(String name, int age) {
		this.name = name;
		this.age = age;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	@Override
	public String toString() {
		return "Student [name=" + name + ", age=" + age + "]";
	}
	
}

public class ArrayListDemo {

	public ArrayListDemo() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		arrayEqualTest();

//		Out.aprintln(""+student1);
//		Out.aprintln(""+student2);
//		Out.aprintln(""+student3);
		
/*		studentsList.add(0, student1);
		studentsList.add(0, student2);
		studentsList.add(0, student3);
		studentsList.add(0, student4);
		studentsList.add(0, student5);*/
		
//		studentsList.add(student1);
//		studentsList.add(student2);
//		studentsList.add(student3);
//		studentsList.add(student4);
//		studentsList.add(student5);
//		studentsList.remove(0);
//		Iterator<Student> iterator = studentsList.iterator();
//		for (Iterator iterator2 = studentsList.iterator(); iterator2.hasNext();) {
//			Student student = (Student) iterator2.next();
//			Out.aprintln(student.toString());
//			
//		}
/*		Out.aprintln(studentsList.get(0).toString());
		studentsList.remove(0);
		Out.aprintln("studentsList.len="+studentsList.size());
		Out.aprintln(studentsList.get(0).toString());
		studentsList.remove(0);
		Out.aprintln("studentsList.len="+studentsList.size());*/
		
		
	}

	public static void arrayEqualTest() {
		// TODO Auto-generated method stub
		List<Student> studentsList = new ArrayList<>();
		List<Student> studentsList2 = new ArrayList<>();
		List<Student> studentsList3 = new ArrayList<>();
		
		Student student1 = new Student("yangdong");
		Student student2 = new Student(23);
		Student student3 = new Student("zhangsan",25);
		Student student4 = new Student("lisi",24);
		Student student5 = new Student("wangwu",26);
		
		studentsList.add(0, student1);
		studentsList.add(0, student2);
		studentsList.add(0, student3);
		studentsList.add(0, student4);
		studentsList.add(0, student5);
		
		studentsList2.add(0, student1);
		studentsList2.add(0, student2);
		studentsList2.add(0, student3);
		studentsList2.add(0, student4);
		studentsList2.add(0, student5);
		
		studentsList3.add(0, student2);
		studentsList3.add(0, student1);
		studentsList3.add(0, student3);
		studentsList3.add(0, student4);
		studentsList3.add(0, student5);
		
/*		Iterator<Student> iterator = studentsList.iterator();
		while (iterator.hasNext()) {
			Student student = (Student) iterator.next();
			if (student.getName() == "zhangsan") {
				studentsList.remove(student3);
			}
		}*/
		
		Iterator<Student> iterator = studentsList.iterator();
		while (iterator.hasNext()) {
			Student student = (Student) iterator.next();
			if (student.getName() == "zhangsan") {
//				studentsList.remove(student3);
				iterator.remove();
			}
		}
		
/*		for (Student student : studentsList) {
			if (student.getName() == "zhangsan") {
				studentsList.remove(student3);
			}
		}*/
		
		
		if (studentsList.equals(studentsList2)) {
			System.out.println("studentsList is the same as studentsList2");
		}
		else {
			System.out.println("studentsList is NOT the same as studentsList2");
		}
		if (studentsList.equals(studentsList3)) {
			System.out.println("studentsList is the same as studentsList3");
		}
		else {
			System.out.println("studentsList is NOT the same as studentsList3");
		}
//		studentsList3.removeAll(studentsList3);
		studentsList3.clear();
		for (Student student : studentsList3) {
			System.out.println(student.toString());
		}
		studentsList3.addAll(studentsList);
		if (studentsList.equals(studentsList3)) {
			System.out.println("studentsList is the same as studentsList3");
		}
		else {
			System.out.println("studentsList is NOT the same as studentsList3");
		}
	}
}
